package main

import (
	"fmt"
	"runtime"
	"sync"
)

var count = 0
var wg sync.WaitGroup
var mutex sync.Mutex
func test()  {
	mutex.Lock()
	defer mutex.Unlock()
	count ++
	fmt.Println(count)
	//time.Sleep(10*time.Millisecond)
	wg.Done()
}

func main() {
	runtime.GOMAXPROCS(4)
	for i := 0; i < 20; i++{
		wg.Add(1)
		go test()
	}

	wg.Wait()
}